//
//  UIColor+Extension.m
//  A6_ 代码颜色自定义视图
//
//  Created by ma c on 16/3/24.
//  Copyright (c) 2016年 ma c. All rights reserved.
//

#import "YJSUIColor+Extension.h"

@implementation UIColor (Extension)

/** 将颜色字符串 转换成*/
+ (UIColor *)colorWithHexString:(NSString *)hexString
{
    //判断字符串长度，前缀
    if (hexString.length ==7 && [hexString hasPrefix:@"#"])
    {
        /**
         #FF FF FF
         R    G   B
         long
         //可以将字符创转换成Long类型的数据
         strtlo(const char *restrict str,char **restrict endptr,int base)
         */
        
        //红色
        NSString *redColorString = [hexString substringWithRange:NSMakeRange(1, 2)];
        NSUInteger redValue = strtol(redColorString.UTF8String, nil, 16);
        //绿色
        NSString *greenColorString = [hexString substringWithRange:NSMakeRange(3, 2)];
        NSUInteger greenValue = strtol(greenColorString.UTF8String, nil, 16);
        //蓝色
        NSString *blueColorString = [hexString substringWithRange:NSMakeRange(5, 2)];
        NSUInteger blueValue = strtol(blueColorString.UTF8String, nil, 16);
        //UIColor
        return [UIColor colorWithRed:redValue/255.0 green:greenValue/255.0 blue:blueValue/255.0 alpha:1.0];
    }
    return nil;
}
@end
